Repository navigation
Conversation
On a resumable Workflow, every resume fast-forwards the runs that finished before it, and _handle_completion re-emitted the output of each one. A run whose output was recovered from the session was therefore stored again on every later resume of the same invocation, so a workflow that parks N times stored its outputs 1 + 2 + ... + N times. Re-emit only an output that the session does not hold yet: one this resume derived from resolved interrupts, as for an answered RequestInput. An output recovered from the session is already persisted. The parallel worker tests expected NodeA's run-1 output to be emitted again on each resume; drop those duplicates from their expectations. Fixes google#8058
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
On a resumable
Workflow, each resume fast-forwards the runs that finished before it, andWorkflow._handle_completioncalls_maybe_reemit_replayed_outputfor every one of them. If a run's output was recovered from the session, it is already persisted, so the re-emit stores it again on every later resume of the same invocation. A workflow that parks N times stores its outputs 1 + 2 + ... + N times, and the session grows quadratically.Solution:
The re-emit covers two kinds of fast-forwarded run, and only one of them needs it:
RequestInput(case 5 incheck_interception). This resume builds the output from the resolved response, so the session does not hold it yet. The re-emit is what persists it, andtest_workflow_request_input_resume[True]depends on that.recovered.output, so it is already in the session._handle_completionnow re-emits only whenrun.recovered_statehas no recovered output:Once the re-emit has persisted an answered park's output, later resumes recover it as case 4 and skip it.
Testing Plan
Unit Tests:
I have added or updated unit tests for my change.
All unit tests pass locally.
New
test_resume_does_not_re_persist_fast_forwarded_outputsintests/unittests/workflow/test_workflow_hitl.py, based on the loop from Resumable Workflow re-persists every fast-forwarded output on each resume: session grows quadratically with the number of resumes #8058 with 4 rounds:mainit fails with 10 stored outputs instead of 4 (ask@1four times,ask@2three times, and so on).test_workflow_parallel_worker.pychanges:test_parallel_worker_pauses_for_human_inputandtest_parallel_worker_hitl_respects_parallel_workers_limitsexpectedNodeA@1's run-1 output to be emitted again on each resume. That is the duplicate this fixes, so I removed it from their run-2/run-3 expectations.Results on this branch, rebased on
main5ce1d0c, Python 3.11:pytest tests/unittests/workflow: 1451 passed, 2 xfailed.pytest tests/unittests: 24793 passed, 94 skipped, 39 xfailed, 2 xpassed, 0 failed.pre-commit run --from-ref origin/main --to-ref HEAD: all hooks pass.test_workflow_request_input_resume[True]fails if the re-emit is removed entirely. It passes with this change, so an answered park's output is still persisted.Manual End-to-End (E2E) Tests:
Run the
repro.pyscript from #8058 (plaingoogle-adk,InMemorySessionService, no model) withpython repro.py 10:Before (
main):After (this branch):
With 100 rounds, the session ends at 1,105 events instead of 6,055, and the script runs in 6.9 s instead of 21 s.
Checklist
Additional context
The 100-round numbers come from the pre-rebase branch at 59b0dd6. The 10-round output above was rerun after rebasing on 5ce1d0c.
This change was developed with AI assistance (Claude Code). The tests and the end-to-end runs above were done locally on Linux with Python 3.11.